package com.ctg.platform.core.security;

import org.apache.commons.lang.StringUtils;

import com.ctg.platform.core.security.Exception.RoleNameException;

public class SecurityUitls {
	public static String parseIntarraytoStr(String[] ids, String s){
		if(ids.length==0)
			return "";
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < ids.length; i++) {
			sb.append("'").append(ids[i]).append("'").append(s);
		}
		return sb.substring(0, sb.length()-1);
	}
	
	public static String buildRoleName(String roleName) throws RoleNameException{
		if(roleName!=null&&!roleName.trim().equals("")){
			roleName = StringUtils.upperCase(roleName);
			if(!roleName.startsWith("ROLE_")){
				roleName = "ROLE_"+roleName;
			}
			while (roleName.contains("__")) {
				roleName = roleName.replace("__", "_");
			}
			if(roleName.equals("ROLE_")){
				roleName = roleName + "AUTO";
			}
		}else{
			throw new RoleNameException("role name can not be empty!");
		}
		return roleName;
	}
	
	public static void main(String[] args) {
		try {
			System.out.println(buildRoleName("rolE________________"));
		} catch (RoleNameException e) {
			e.printStackTrace();
		}
	}
}
